package top.huhuiyu.myimages.convert;

import java.math.BigDecimal;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class MyDecimalConverter implements Converter<String, BigDecimal> {

	public static final BigDecimal ZERO = new BigDecimal("0");

	public static boolean isEmpty(BigDecimal dec) {
		return dec == null || dec.compareTo(ZERO) <= 0;
	}

	@Override
	public BigDecimal convert(String source) {
		if (source == null || source.trim().equals("")) {
			return ZERO;
		}
		try {
			return new BigDecimal(source);
		} catch (Exception e) {
			return ZERO;
		}

	}

}
